package com.zhengtoudai.ui.presenter;

import com.zhengtoudai.ui.bean.Result;
import com.zhengtoudai.http.HttpApi;
import com.zhengtoudai.injector.PerActivity;
import com.zhengtoudai.ui.view.VerificationCodeView;

import javax.inject.Inject;

import rx.Subscriber;
import rx.functions.Action0;

/**
 * Created by Administrator on 2016/8/24 0024.
 */
@PerActivity
public class VerificationCodePresenterImpl extends BasePresenterImpl<VerificationCodeView> implements VerificationCodePresenter {

    @Inject
    public VerificationCodePresenterImpl() {

    }

    @Override
    public void getSMSCode(String mobile) {
        mSubscription=HttpApi.getInstance().getSMSCode(mobile)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
                        mView.showSMSDialog();
                    }
                })
                .subscribe(new Subscriber<Result>() {
                    @Override
                    public void onCompleted() {
                        mView.dismissSMSDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.onSMSFailure(e);
                        mView.dismissSMSDialog();
                    }

                    @Override
                    public void onNext(Result result) {
                       mView.onSMSResult(result);

                    }
                });

    }

}
